home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 17 / CU Amiga Magazine's Super CD-ROM 17 (1997)(EMAP Images)(GB)[!][issue 1997-12].iso / CUCD / Programming / DiceSource / src / dutil / istrip.c < prev    next >
C/C++ Source or Header  |  1997-09-09  |  2KB  |  123 lines

  1. /*
  2.  *    (c)Copyright 1992-1997 Obvious Implementations Corp.  Redistribution and
  3.  *    use is allowed under the terms of the DICE-LICENSE FILE,
  4.  *    DICE-LICENSE.TXT.
  5.  */
  6.  
  7. /*
  8.  *  ISTRIP.C
  9.  *
  10.  *  ISTRIP destprefix wildcards
  11.  *
  12.  *
  13.  *  Strips the files specified by the wildcard and generates files by
  14.  *  prefixing each file with the destprefix.
  15.  */
  16.  
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #ifdef AMIGA
  20. #include <lib/version.h>
  21. #else
  22. #include <include/lib/version.h>
  23. #endif
  24.  
  25. IDENT("istrip",".3");
  26. DCOPYRIGHT;
  27.  
  28. void StripFile(char *, char *);
  29.  
  30. int
  31. main(int ac, char **av)
  32. {
  33.     int   i;
  34.  
  35.     if (ac == 1) {
  36.     puts(Ident);
  37.     puts(DCopyright);
  38.     puts("istrip destprefix wildcards");
  39.     exit(1);
  40.     }
  41.  
  42. #ifdef AMIGA
  43.     expand_args(ac, av, &ac, &av);
  44. #endif
  45.  
  46.     for (i = 2; i < ac; ++i) {
  47.     char buf[256];
  48.     sprintf(buf, "%s%s", av[1], av[i]);
  49.     StripFile(av[i], buf);
  50.     puts("");
  51.     }
  52.     return(0);
  53. }
  54.  
  55. void
  56. StripFile(sname, dname)
  57. char *sname;
  58. char *dname;
  59. {
  60.     FILE *fi;
  61.     FILE *fo;
  62.     short c;
  63.     short firstComment = 1;
  64.  
  65.     printf("%-20s %-20s ", sname, dname);
  66.     fflush(stdout);
  67.     fi = fopen(sname, "r");
  68.     if (fi == NULL) {
  69.     puts("unable to open source");
  70.     return;
  71.     }
  72.     fo = fopen(dname, "w");
  73.     if (fo == NULL) {
  74.     puts("unable to open dest");
  75.     fclose(fi);
  76.     return;
  77.     }
  78.     while ((c = getc(fi)) != EOF) {
  79.     switch(c) {
  80.     case '/':       /*  look for comment    */
  81.         c = getc(fi);
  82.         if (c != '*') {
  83.         fputc('/', fo);
  84.         fputc(c, fo);
  85.         continue;
  86.         }
  87.         if (c == '*' && firstComment == 1) {
  88.         firstComment = 0;
  89.         fputc('/', fo);
  90.         fputc(c, fo);
  91.         continue;
  92.         }
  93.         for (;;) {
  94.         if (c == EOF)
  95.             break;
  96.         if (c == '*') {
  97.             c = getc(fi);
  98.             if (c != '/')
  99.             continue;
  100.             break;
  101.         } else {
  102.             c = getc(fi);
  103.         }
  104.         }
  105.         break;
  106.     case ' ':
  107.     case 9:
  108.         while (c == 9 || c == ' ')
  109.         c = getc(fi);
  110.         if (c != EOF)
  111.         ungetc(c, fi);
  112.         putc(' ', fo);
  113.         break;
  114.     default:
  115.         putc(c, fo);
  116.         break;
  117.     }
  118.     }
  119.     fclose(fi);
  120.     fclose(fo);
  121. }
  122.  
  123.